package com.homework2.demo3;

import java.util.Objects;

public class Teacher implements Comparable<Teacher>{
    private String name;
    private int age;
    private int salary;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(int salary) {
        this.salary = salary;
    }

    public Teacher(String name, int age, int salary) {
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Teacher teacher = (Teacher) o;
        if (age != teacher.age) return false;
        return Objects.equals(name, teacher.name);
    }


    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + age;
        return result;
    }

    @Override
    public String toString() {
        return "Teacher{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", salary=" + salary +
                '}';
    }


    //按照age的大小来排序，如果age相同，则继续按salary的大小来排序
    @Override
    public int compareTo(Teacher t2) {
        int compare = Integer.compare(this.age, t2.age);
        if (compare == 0) {
            return Double.compare(this.salary, t2.salary);
        }
        return compare;

    }

}
